import {computed} from 'vue'
import {useRouter} from 'vue-router'

const routerJump = () => {
    const router = useRouter();
    const toPage = path => router.push(path)
    return {
        toPage
    }
}
const PathToSign = () => {
    const router = useRouter();
    // const title = ref('I’M')
    // const des = ref('Mark')
    // watch(router.currentRoute, ({path, name}) => {
    //     const condition = path === '/' ? 'I’M' : '';
    //     title.value = condition;

    //     const condition2 = path === '/' ? 'Mark' : name;
    //     des.value = condition2;
    // }, {
    //     immediate: true
    // })
    /**
     * 以上watch等同于 watchEffect
    */
    // watchEffect(() => {
    //     const { path, name } = router.currentRoute.value
    //     const condition = path === '/' ? 'I’M' : '';
    //     title.value = condition;
    //     const condition2 = path === '/' ? 'Mark' : name;
    //     des.value = condition2;
    // })
    /**
     * 用计算属性的方式实现
    */
    const title = computed(() => {
        const { path } = router.currentRoute.value;
        return path === '/' ? 'I’M' : ''
    })
    const des = computed(() => {
        const { path, name } = router.currentRoute.value;
        return path === '/' ? 'Mark' : name
    })
    return {
        src: require("../assets/img/wr_user.jpeg"),
        title,
        des
    }
}
export {routerJump, PathToSign}